// pages/trucks/my/my.js
const app = getApp()
var tab = require('../../../components/tabbar/tabbar.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    infor: {}, //获取信息
    myPhone: '', //个人手机号
    phone: '' //联系客服
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    tab.tabbar("tabBar", 2, this); //0表示第一个tabbar
    this.contart();
  },
  onShow: function () {
    this.getInfor();
  },
  // 下拉刷新
  onPullDownRefresh: function () {
    wx.showNavigationBarLoading(); //在标题栏中显示加载
    this.getInfor();
    this.contart();
  },
  //编辑资料
  edit() {
    wx.navigateTo({
      url: '/pages/trucks/my/editInfor/editInfor',
    })
  },
  //已认证/未认证
  approve() {
    if(this.data.infor.examine!=2) {
      wx.showToast({
        title: '请等待后台审核',
        icon: 'none',
        mask: true
      })
    }else{
      wx.navigateTo({
        url: '/pages/trucks/my/editInfor/editInfor'
      })
    }
  },
  //我的会员
  member() {
    wx.navigateTo({
      url: '/pages/trucks/my/memberCenter/memberCenter',
    })
  },
  //发货记录
  record() {
    wx.navigateTo({
      url: '/pages/trucks/my/record/record',
    })
  },
  //意见反馈
  // feedback() {
  //   wx.navigateTo({
  //     url: '/pages/trucks/my/feedback/feedback?name=' + this.data.infor.name
  //   })
  // },
  //法律公告
  legal() {
    wx.navigateTo({
      url: '/pages/trucks/my/legal/legal',
    })
  },
  //个人信息
  getInfor() {
    wx.request({
      url: app.globalData.url + 'api/v1/goods/goodsresources/information',
      method: 'GET',
      data: {
        id: wx.getStorageSync('id')
      },
      success: res => {
        console.log(res)
        if(res.data.code == 200) {
          let phone = res.data.data.phone.substring(0, 3) + '****' + res.data.data.phone.substring(7)
          this.setData({
            infor: res.data.data,
            myPhone: phone
          })
        }
      },
      fail: err => {
        console.log(err)
      },
      complete: e => {
        console.log(e)
        wx.hideNavigationBarLoading() //完成停止加载
        wx.stopPullDownRefresh() //停止下拉刷新
      }
    })
  },
  //联系客服
  contart() {
    wx.request({
      url: app.globalData.url + 'api/v1/news/service',
      method: 'GET',
      success: res => {
        console.log(res)
        if(res.data.code == 200) {
          this.setData({
            phone: res.data.data.data
          })
        }
      },
      fail: err => {
        console.log(err)
      },
      complete: e => {
        console.log(e)
        wx.hideNavigationBarLoading() //完成停止加载
        wx.stopPullDownRefresh() //停止下拉刷新
      }
    })
  },
  //拨打电话
  getPhone() {
    wx.makePhoneCall({
      phoneNumber: this.data.phone,
      success: res => {
        console.log(res)
      },
      fail: res => {
        console.log(res);
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})